package com.quan.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.quan.admin.entity.SysPermission;
import com.quan.admin.mapper.SysPermissionMapper;
import com.quan.admin.service.SysPermissionService;
import com.quan.commons.core.biz.support.MyBaseServiceImpl;
import com.quan.commons.core.utils.PageUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;


@Service
public class SysPermissionServiceImpl extends MyBaseServiceImpl<SysPermissionMapper, SysPermission> implements SysPermissionService {

    @Autowired
	private SysPermissionMapper mapper;

	@Override
    public IPage<SysPermission> selectMyPage(PageUtils pageUtils, SysPermission entity) {
        Page<SysPermission> page = new Page<SysPermission>(pageUtils.getPage(), pageUtils.getLimit());

        // 排序
        super.handleSort(page, pageUtils);

        return this.mapper.selectMyPage(page, entity);
    }

    @Override
    public List<SysPermission> findPermissionByMenuId(Serializable menuId) {

        QueryWrapper<SysPermission> queryWrapper = new QueryWrapper<SysPermission>();
        queryWrapper.eq("menu_id", menuId);

        return super.list(queryWrapper);
    }

    @Override
    public boolean deleteByMenuId(Serializable menuId) {
        QueryWrapper<SysPermission> wrapper = new QueryWrapper<SysPermission>();
        wrapper.eq("menu_id", menuId);
        return super.remove(wrapper);
    }

}